/**
 * 
 */
package com.gragra.processText;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Collection;
import java.util.Map;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
/**
 * @author Christoph Teichmann
 * created Jan 26, 2013 1:55:44 PM
 * @version 0.1
 */
public class MapToClusters
{
	/**
	 *
	 * @param sw
	 * @param bw 
	 * @throws IOException 
	 */
	public static void map(StringWriter sw, BufferedWriter bw) throws IOException
	{
		String[] parts = sw.toString().split("\n");
		boolean first = true;
		Multimap<String, String> mm = HashMultimap.create();
		for (int i = 0; i < parts.length; i++)
		{
			String[] elems = parts[i].split(" : ");
			mm.put(elems[1], elems[0]);
		}
		for(Map.Entry<String, Collection<String>> ent : mm.asMap().entrySet())
		{
			if(first)
			{first = false;}
			else
			{bw.newLine();}
			bw.write(ent.getKey());
			bw.write(" :");
			for(String s : ent.getValue())
			{
				bw.write(" ");
				bw.write(s);
			}
		}
		bw.flush();
	}
}